package com.gree.flowable.app.tools.constants;

public enum OracleColumnsEnum {
    String("VARCHAR2", 32),
    Integer("NUMBER", 0),
    Double("BINARY_DOUBLE", 0),
    Date("NUMBER", 10),
    Time("VARCHAR2", 10),
    Blob("VARCHAR2",1000),
    ;
    private String name;
    private Integer length;

    /**
     * Type 枚举类型---String
     * name ---varchar
     */

    /**
     * 通过Type获取数据库字段name
     */
    public static String getColumnsByType(String type) {
        for (OracleColumnsEnum e : OracleColumnsEnum.values()) {
            if (e.name().equals(type)) {
                return e.getName();
            }
        }
        return "";
    }

    /**
     * 通过Type获取枚举长度
     */
    public static Integer getLengThByType(String type) {
        for (OracleColumnsEnum e : OracleColumnsEnum.values()) {
            if (e.name().equals(type)) {
                return e.getLength();
            }
        }
        return 0;
    }

    /**
     * 通过name跟length判断枚举的属性
     */
    public static String getEnumByName(String name, Integer length) {
        for (OracleColumnsEnum e : OracleColumnsEnum.values()) {
            if (e.getName().equals(name)) {
                if ("VARCHAR2".equals(name)){
                    if (length != null && length == 10){
                        return OracleColumnsEnum.Time.name();
                    }else if(length != null && length == 1000){
                        return OracleColumnsEnum.Blob.name();
                    }else{
                        return OracleColumnsEnum.String.name();
                    }
                }else{
                    if ("NUMBER".equals(name)){
                        if (length != null && length == 10){
                            return OracleColumnsEnum.Date.name();
                        }
                    }
                    return e.name();
                }
            }
        }
        return "";
    }

    OracleColumnsEnum(String name, Integer length) {
        this.name = name;
        this.length = length;
    }

    public java.lang.String getName() {
        return name;
    }

    public void setName(java.lang.String name) {
        this.name = name;
    }

    public java.lang.Integer getLength() {
        return length;
    }

    public void setLength(java.lang.Integer length) {
        this.length = length;
    }
}
